/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            applyReturnOrderManageInfo: {
                rsId: '',
                supplierName: '',
                orders: [],
                remark: '',
                totalMount: 0.00,
                orderType: '10000',
                shopId: vc.getCurrentCommunity().shopId
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('applyReturnOrderManage', 'chooseStoreOrder', function (_product) {
                $that.applyReturnOrderManageInfo.orders.push(_product);
            });
        },
        methods: {
            _doInoutOrder: function () {
                let _orders = $that.applyReturnOrderManageInfo.orders;
                if (_orders.length < 1) {
                    vc.toast('请选择商品');
                    return;
                }
                vc.http.apiPost(
                    '/storeOrderCartReturn/applyReturnStoreCarts',
                    JSON.stringify($that.applyReturnOrderManageInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            vc.toast(_json.msg);
                            vc.goBack();
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _openAddShopHouseModal: function () {
                vc.emit('chooseStoreOrder', 'openChooseProductModel', {});
            },
            _goBack: function () {
                vc.goBack();
            },
            _deleteProduct: function (_inoutOrderProduct) {
                let _orders = $that.applyReturnOrderManageInfo.orders;
                let index = _orders.indexOf(_inoutOrderProduct);
                if (index > -1) {
                    _orders.splice(index, 1);
                }
            },
            _changeResourceSupp: function (_rsId) {
                $that.applyReturnOrderManageInfo.resourceSuppliers.forEach(item => {
                    if (item.rsId == _rsId) {
                        $that.applyReturnOrderManageInfo.resourceSuppliers = item.supplierName;
                    }
                });
            },
            _caculTotalMount: function () {
                let j = 0;
                $that.applyReturnOrderManageInfo.orders.forEach(item => {
                    if (!isNaN(item.cartNum) && !isNaN(item.price)) {
                        j += parseFloat(item.returnCartNum) * parseFloat(item.price).toFixed(2);
                    } else {
                        $that.applyReturnOrderManageInfo.totalMount = "请输入正确的数字";
                        throw Error();
                    }
                });
                $that.applyReturnOrderManageInfo.totalMount = j.toFixed(2);
            }
        }
    });
})(window.vc);
